<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form
        layout="inline"
        labelAlign="right"
        :labelCol="{ style: 'width: 100px' }"
        @keyup.enter.native="searchQuery"
      >
        <a-row :gutter="5">
          <a-col :md="5" :sm="24">
            <a-form-item label="起始时间">
              <a-date-picker
                v-model="queryParam.startTime"
                :disabled-date="disabledStartDate"
                style="width:100%"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
              />
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="24">
            <a-form-item label="终止时间">
              <a-date-picker
                v-model="queryParam.endTime"
                :disabled-date="disabledEndDate"
                style="width:100%"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
              />
            </a-form-item>
          </a-col>
          <!-- <a-col :md="5" :sm="24">
            <a-form-item label="设备位置">
              <a-select v-model="alarmLocations" mode="multiple" placeholder="请选择设备位置" :show-arrow='true'  @change="alarmLocationChange">
                  <a-select-option value="SYS">站台</a-select-option>
                  <a-select-option value="UP">上行</a-select-option>
                  <a-select-option value="DOWN">下行</a-select-option>
              </a-select>                 
            </a-form-item>
          </a-col> -->
          <a-col :md="5" :sm="24">
            <a-form-item label="预警位置">
              <a-tree-select
                v-model="locations"
                style="width: 100%"
                class="treeSelect"
                :tree-data="equipData"
                tree-checkable
                :show-checked-strategy="SHOW_CHILD"
                placeholder="请选择预警位置"
                :maxTagCount="0"
                :dropdownStyle="{ height: '280px' }"
                :show-arrow="true"
                @change="alarmDeviceCodesChange"
              />
            </a-form-item>
          </a-col>
          <!-- <a-col :md="5" :sm="24">
            <a-form-item label="设备类型">
              <a-input placeholder="请选择设备类型" v-model="queryParam.faultTypeCode"></a-input>
            </a-form-item>
          </a-col>                    -->
          <a-col :md="5" :sm="24">
            <a-form-item label="预警级别">
              <a-select
                placeholder="请选择预警级别"
                v-model="alarmLevels"
                mode="multiple"
                :show-arrow="true"
                @change="alarmLevelChange"
              >
                <a-select-option value="一级">故障</a-select-option>
                <a-select-option value="二级">报警</a-select-option>
                <!-- <a-select-option value="三级">三级</a-select-option> -->
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
              <!-- <a @click="advanced=!advanced" style="margin-left: 8px;">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'" />
              </a> -->
            </span>
          </a-col>

          <!-- <a-col :md="5" :sm="24">
            <a-form-item label="健康值">
              <a-select placeholder="请选择健康值" v-model="queryParam.healthyType">
                <a-select-option v-for="item in healthTypeArr" :value="item.id" :key="item.id">{{ item.typeName }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>           -->
          <!-- <a-col :md="5" :sm="24">
            <a-form-item label="设备类型">
              <a-input placeholder="请输入设备类型" v-model="queryParam.faultTypeCode"></a-input>
            </a-form-item>
          </a-col> -->
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <span slot="alarmLevel" slot-scope="text">
          {{ text == '一级' ? '故障' : '报警' }}
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>

          <!-- <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
        </span>
      </a-table>
    </div>

    <!-- <gd-device-healthy-alarm-modal ref="modalForm" @ok="modalFormOk"></gd-device-healthy-alarm-modal> -->
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
// import GdDeviceHealthyAlarmModal from './modules/GdDeviceHealthyAlarmModal'
import { TreeSelect } from 'ant-design-vue'
const SHOW_CHILD = TreeSelect.SHOW_CHILD
import moment from 'moment'
export default {
  name: 'GdDeviceHealthyAlarmList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    // GdDeviceHealthyAlarmModal
  },
  data() {
    return {
      description: '设备健康预警管理页面',
      queryParam: {
        startTime: moment()
          .subtract(30, 'day')
          .format('YYYY-MM-DD HH:00:00'),
        endTime: moment().format('YYYY-MM-DD HH:00:00'),
        locations: [],
        alarmLevels: []
      },
      advanced: false,
      SHOW_CHILD,
      equipData: [],
      // 表头
      columns: [
        // {
        //   title: '#',
        //   dataIndex: '',
        //   key:'rowIndex',
        //   width:60,
        //   align:"center",
        //   customRender:function (t,r,index) {
        //     return parseInt(index)+1;
        //   }
        // },
        // {
        //   title:'预警ID',
        //   align:"center",
        //   dataIndex: 'id'
        // },
        {
          title: '预警时间',
          align: 'center',
          dataIndex: 'alarmTime',
          width: '260px'
          // customRender:function (text) {
          //   return !text?"":(text.length>10?text.substr(0,10):text)
          // }
        },
        // {
        //   title:'预警级别',
        //   align:"center",
        //   dataIndex: ''
        // },
        {
          title: '设备位置',
          align: 'center',
          dataIndex: 'alarmLocation'
        },
        {
          title: '预警编号',
          align: 'center',
          dataIndex: 'alarmDeviceCode'
        },
        {
          title: '预警级别',
          align: 'center',
          dataIndex: 'alarmLevel',
          scopedSlots: { customRender: 'alarmLevel' }
        },
        // {
        //   title:'设备名称',
        //   align:"center",
        //   dataIndex: 'alarmDeviceName'
        // },
        {
          title: '预警名称',
          align: 'center',
          dataIndex: 'faultType'
        },
        // {
        //   title:'处理状态',
        //   align:"center",
        //   dataIndex: 'status_dictText'
        // },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/healthy/gdDeviceHealthyAlarm/list',
        delete: '/healthy/gdDeviceHealthyAlarm/delete',
        deleteBatch: '/healthy/gdDeviceHealthyAlarm/deleteBatch',
        exportXlsUrl: '/healthy/gdDeviceHealthyAlarm/exportXls',
        importExcelUrl: 'healthy/gdDeviceHealthyAlarm/importExcel'
      },
      superFieldList: [],
      alarmDeviceNames: [],
      alarmLocations: [],
      locations: [],
      alarmLevels: []
    }
  },
  created() {
    // this.dataSource=[{id:1,alarmDeviceName:'mock'},{id:2,alarmDeviceName:'mock'}]
    this.getHealthType()
    this.getEquipData() //编号
  },
  computed: {
    // importExcelUrl: function(){
    //   return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    // },
  },
  methods: {
    moment,
    disabledStartDate(startValue) {
      // const endValue = this.form.endTime;
      // if (!startValue || !endValue) {
      //   return false;
      // }
      // return startValue.valueOf() > moment(endValue).valueOf();
      return startValue.valueOf() > moment().valueOf()
    },
    disabledEndDate(endValue) {
      // const startValue = this.form.startTime;
      // if (!endValue || !startValue) {
      //   return false;
      // }
      // return  moment(startValue).valueOf() >= endValue.valueOf();
      return endValue.valueOf() > moment().valueOf()
    },
    handleDetail(data) {
      this.$router.push({ path: '/health/healthWarningList/Detail', query: { id: data.id } })
    },
    // 设备名称
    alarmDeviceNamesChange(val) {
      this.queryParam.alarmDeviceNames = val.join(',')
    },
    alarmLocationChange(value) {
      this.queryParam.alarmLocations = value.join(',')
    },
    // 设备编号
    alarmDeviceCodesChange(val) {
      this.queryParam.locations = val.join(',')
    },
    alarmLevelChange(val) {
      this.queryParam.alarmLevels = val.join(',')
    },
    searchReset() {
      this.queryParam = {
        startTime: moment()
          .subtract(30, 'day')
          .format('YYYY-MM-DD HH:00:00'),
        endTime: moment().format('YYYY-MM-DD HH:00:00'),
        locations: '',
        alarmLevels: ''
      }
      this.locations = []
      this.alarmDeviceNames = []
      this.alarmLevels = []
    }
  }
}
</script>
<style scoped lang="less">
@import '~@assets/less/common.less';
.treeSelect {
  /deep/.ant-select-selection--multiple .ant-select-selection__choice {
    visibility: hidden;
  }
  /deep/.ant-select-search__field {
    visibility: hidden;
  }
}
</style>
